<!--
 * @Author: your name
 * @Date: 2022-03-28 15:14:37
 * @LastEditTime: 2024-06-28
 * @LastEditors: Tommy Chen
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /macc.admin.vue/src/views/system/usercenter/index.vue
-->
<template>
  <div class="main-content1">
    <div class="left-item">
      <div class="accout-title">{{ $t('userManage.account') }}</div>
      <div
        :class="['menu-item', currentAnchor == item.id ? 'visited' : '']"
        v-for="(item, index) in menuList"
        @click="linkClick(item.id)"
        :key="index"
      >
        {{ item.title }}
      </div>
    </div>
    <div class="right-item" id="rightContent">
      <div style="width: 800px">
        <div id="a01">
          <BaseInfo v-if="!isIntl" />
        </div>
        <div id="a01">
          <BaseInfoIntl v-if="isIntl" />
        </div>
        <template v-if="!isAADAccount">
          <div id="a03">
            <PasswordIntl v-if="isIntl" />
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import BaseInfo from './components/BaseInfo.vue';
import PasswordIntl from './components/passwordIntl';
import BaseInfoIntl from './components/baseInfoIntl.vue';
import { maccApi, requestHttp } from '@utils/index';

export default {
  name: 'Usercenter',
  components: {
    BaseInfo,
    PasswordIntl,
    BaseInfoIntl,
  },
  computed: {
    ...mapState('User', ['userInfo']),
    isAADAccount() {
      return this.userInfo.azureObjectId ? true : false;
    },
    isIntl() {
      return process.env.VUE_APP_MACC_ENV === 'INTL';
    },
  },
  data() {
    return {
      currentAnchor: 'a01',
      isPaidAccount: false,
      menuList: [],
    };
  },
  mounted() {
    this.initView();
  },
  methods: {
    async initView() {
      let list = [
        {
          title: this.$t('account.basic'),
          id: 'a01',
        },
      ];
      await this.checkPaidAccount();
      if (this.isIntl) {
        list.push({
          title: this.$t('account.editPwd'),
          id: 'a03',
        });
      }
      this.menuList = list;
    },
    linkClick(id) {
      this.currentAnchor = id;
      this.setScrollTop();
    },
    //页面滚动 锚点高亮显示
    linkMouseOver(id) {
      this.currentAnchor = id;
    },
    setScrollTop() {
      let top =
        document.querySelector('#' + this.currentAnchor).offsetTop -
        document.querySelector('#a01').offsetTop;
      document.querySelector('#rightContent').scroll({
        top: top,
        behavior: 'smooth',
        block: 'nearest',
        inline: 'nearest',
      });
    },
    //判断是否已激活账号
    async checkPaidAccount() {
      if (this.isIntl) {
        const api = maccApi.ACTIVATE_CLIENT_GET_API.replace(
          '{account}',
          this.userInfo.account
        );
        const { code } = await requestHttp({ api, method: 'GET' });
        if (code == 0 || code == 1045) {
          this.isPaidAccount = true;
        }
      }
    },
  },
};
</script>

<style scoped lang="less">
.main-content1 {
  width: 100%;

  padding: 4px;
  font-size: 14px;
  color: #333;
  height: 100%;
  bottom: 0px;
  text-align: left;
  background: #f0f3f6 !important;
  display: flex;
  .accout-title {
    font-size: 20px;
    font-weight: bold;
    color: @gray-10;
    padding: 16px;
  }
  .left-item {
    display: flex;
    flex-direction: column;
  }
  .right-item {
    flex: 1;
    display: flex;
    justify-content: center;
    overflow: auto;
    margin: 0px 50px;
    background: #fff;
    padding-top: 20px;
  }
  .menu-item {
    padding: 8px;
    min-width: 240px;
    cursor: pointer;
    margin-bottom: 8px;
    position: relative;
  }
  .border-left {
    border-left: 1px solid @ryblue-6;
  }
  .visited {
    background-color: @gray-1;
    font-weight: bold;
    border-left: 3px solid @ryblue-6;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
    // &::after {
    //   border-left: 3px solid @ryblue-6;
    //   content: '';
    //   position: absolute;
    //   left: 2px;
    //   height: 16px;
    //   vertical-align: middle;
    //   top: 10px;
    //   left: -1px;
    // }
  }
}
</style>
